﻿using System;

namespace MoreExtentions
{
    public static partial class Linq
    {
        /// <summary>
        /// Determines whether [has value and equals] [the specified source].
        /// int? index = GetIndex();
        /// if (index.HasValueAndEquals(10))...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        /// 	<c>true</c> if [has value and equals] [the specified source]; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasValueAndEquals<T>(this T? source, T target) where T : struct
        {
            return source.HasValue && source.Value.Equals(target);
        }

        /// <summary>
        /// Determines whether [has value and equals] [the specified source].
        /// int? index = GetIndex();
        /// if (index.HasValueAndEquals(10))...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <returns>
        /// 	<c>true</c> if [has value and equals] [the specified source]; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasValueAndEquals<T>(this T? source, T? target) where T : struct
        {
            return source.HasValue && source.Value.Equals(target);
        }
    }
}